<template>
  <div p-5>
    <DynamicTable
      ref="dynamicTableRef"
      bordered
      :data-request="loadData"
      :columns="columns"
      row-key="heroid"
      :scroll="{
        y: 'calc(100vh - 315px)',
      }"
    >
    </DynamicTable>
  </div>
</template>

<script lang="ts" setup>
  import { useRouter } from 'vue-router';
  import { Taskcolumns, type TableColumnItem } from './columns';
  import { useTable } from '@/components/core/dynamic-table';
  import { getList } from '@/api/supervision/taskApproval';

  const tableHeight = 'calc(100vh - 500px)';
  const router = useRouter();
  const [DynamicTable, dynamicTableInstance] = useTable();

  const loadData = async (params): Promise<API.TableListResult> => {
    const data = await getList(params);
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          list: data,
          ...params,
        });
      }, 500);
    });
  };

  const columns: TableColumnItem[] = [
    ...Taskcolumns,
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 160,
      dataIndex: 'ACTION',
      actions: ({ record }) => [
        {
          label: '详情',
          ifShow: record.approveType == 1,
          onClick: () =>
            router.push({
              path: '/supervision/taskApproval',
              query: {
                id: record.id,
                progressId: record.progressId,
                isCheck: '1',
              },
            }),
        },
        {
          label: '审批',
          ifShow: record.approveType == 0,
          onClick: () =>
            router.push({
              path: '/supervision/taskApproval',
              query: { id: record.id, progressId: record.progressId, isCheck: '2' },
            }),
        },
      ],
    },
  ];
</script>

<style lang="less" scoped></style>
